#include <string.h>

#include "lib.h"

#include "getnpair.h"
#include "opthelpr.h"

GetNPair::GetNPair(uint8* counts)
{
	this->counts = counts;

	i = 0;
	usedjoker = false;
	pair[1] = pair[2] = (uint8*)0;

	pair[i] = has_ofAKind(2);

	while (i < 3 && pair[i])
	{
		if (++i >= 3)
			break;

		pair[i] = hasMore_ofAKind(2, pair[i - 1] + 1);
	}

	if (i < 3 && HASACE() && HASJOKER())
	{
		pair[i++] = counts + COUNTNDX(ACERANK);
		usedjoker = true;
	}

	ASSERT(i >= 1 && i <= 3);
}

int32
GetNPair::getPairRank(int32 n)
{
	ASSERT(n >= 0 && n <= i);

	return RANKPTR(pair[n]);
}
